﻿package org.openChart.sprite 
{
	
	/**
	 * 
	 * @author Chongyuan
	 */
	public class Color 
	{
		private var red:uint;
		private var green:uint;
		private var blue:uint;
		
		public function Color( color:uint) 
		{
			this.color = color;
		}
		
		/**
		 * Get 
		 * @param	weight
		 * @return
		 */
		public function getLighter( weight:Number = 0.1 ):uint
		{
			var blueTem:uint = weight * 0.114 * blue + blue;
			var greenTem:uint = weight * 0.587 * green + green;
			var redTem:uint = red * 0.299 * weight + red;
			if (blueTem > 255)
				blueTem = 255;
			if (redTem > 255)
				redTem = 255;
			if (greenTem > 255)
			    greenTem = 255;

			return (redTem << 16) + (greenTem << 8) + blueTem;
		}
		
		/**
		 * Get the 
		 * @param	weight
		 * @return
		 */
		public function getDarker(weight:Number = 0.1 ):uint
		{
			var blueTem:uint = blue - weight * 0.114 * blue ;
			var greenTem:uint = green - weight * 0.587 * green ;
			var redTem:uint = red - red * 0.299 * weight ;

			return (redTem << 16) + (greenTem << 8) + blueTem;
		}
		
		public function getColor():uint
		{
			return (red << 16) + (green << 8) + blue; 
		}
		
		public function set color( color:uint ):void
		{
			blue = color & 0x0000FF;
			green = (color & 0x00FF00) >> 8;
			red = (color & 0xFF0000) >> 16;
		}
	}
	
}